var payId="";
var content_url = window.location.href;
content_url = content_url.split("?");
payId = content_url[ content_url.length-1 ].split("=")[ content_url[ content_url.length-1 ].split("=").length-1 ];
console.log(payId);

$.ajax({
    url:url+"v1/order/detail",
    method:"GET",
    dataType:"json",
    data:{
        orderId:payId
    },
    xhrFields: {
        withCredentials: true // 允许跨域名储存和访问cookie
    }
}).done(function(data){
    console.log(data);
    var order=data.data.order;
    if(data.code="success"){
        $(".payCancel").find("div").remove();
        
        var create_time=moment(order.create_time).format('YYYY-MM-DD');
        var check_in_time=moment(order.check_in_time).format('YYYY-MM-DD');
        var check_out_time=moment(order.check_out_time).format('YYYY-MM-DD');
        var str="";
        str+=`
            <div class="payCancel_main">
                <div class="payCancel_order">
                    <div class="payCancel_order_title">
                            订单信息
                    </div>
                    <div class="payCancel_order_msg">
                        <ul>
                            <li><span>订单编号：</span> `+order.orderNo+`</li>
                            <li><span>酒　　店：</span> `+order.hotel.name+`</li>
                            <li><span>房　　型：</span> `+order.roomName+`</li>
                            <li><span>预定时间：</span> `+create_time+`</li>
                            <li><span>入住时间段：</span> `+check_in_time+`至`+check_out_time+`</li>
                        </ul>
                    </div>
                </div>
                <div class="payCancel_check_in">
                    <div class="payCancel_check_title">
                            入住信息
                    </div>
                    <div class="payCancel_check_msg">
                        <p><span>客人姓名：</span>  `+order.customerName+`</p>
                        <p><span>手机号码：</span>  `+order.customerPhone+`</p>
                    </div>
                </div>
            </div>
            <div class="cancelBtn">
                取消订单
            </div>
        `;
        $(".payCancel").append(str);
    }
})


$(".cancelBtn").click(function(){
    $.ajax({
        url:url+"v1/order/cancle",
        method:"POST",
        dataType:"json",
        data:{
            token:localStorage.token,
            orderId:payId
        },
        xhrFields: {
            withCredentials: true // 允许跨域名储存和访问cookie
        }
    }).done(function(data){
        console.log(data);
        if(data.code="success"){
            alert("取消成功");
            
        }
    })
})
